﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using IFDB.ResourceLibrary;

namespace IFDB.Models.Tables
{
    public class Competition
    {
        public Competition()
        {
            this.Matches = new HashSet<Match>();
        }

        [Key]
        public Guid CompetitionId { get; set; }
        public Country Country { get; set; }
        public CompetitionType CompetitionType { get; set; }

        [StringLength(50)]
        public string CompetitionName { get; set; }

        [StringLength(15)]
        public string ShortName { get; set; }
        public Nullable<short> Rank { get; set; }
        public Nullable<short> Round { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }

        public virtual ICollection<Match> Matches { get; set; }

        public static Competition CreateNew(Country country, CompetitionType competitionType, string competitionName, string shortName, short? rank, short? round, DateTime startDate, DateTime endDate)
        {
            return new Competition()
            {
                CompetitionId = Guid.NewGuid(),
                Country = country,
                CompetitionType = competitionType,
                CompetitionName = competitionName,
                ShortName = shortName,
                Rank = rank,
                Round = round,
                StartDate = startDate,
                EndDate = endDate
            };
        }

        public static void Update(Competition competition, Country country, CompetitionType competitionType, string competitionName, string shortName, short? rank, short? round, DateTime startDate, DateTime endDate)
        {
            competition.Country = country;
            competition.CompetitionType = competitionType;
            competition.CompetitionName = competitionName;
            competition.ShortName = shortName;
            competition.Rank = rank;
            competition.Round = round;
            competition.StartDate = startDate;
            competition.EndDate = endDate;
        }
    }
}
